package avicit.im.lantop.basic.fieldmapset.service.api;

import avicit.im.lantop.basic.fieldmapset.domain.LantopFieldRelateSet;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import avicit.platform6.core.jdbc.Page;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class LantopFieldMapSetServiceApi {



    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/im/lantop/basic/fieldmapset/action/rest/LantopFieldMapSetServiceRest";

    @Autowired
    private RestClient restClient;


    /**
     *获取选择库表树NODES
     * @param root
     * @param type
     * @param flag
     * @param sOrt
     * @param orgId
     * @return
     */
    public List<TreeNode> selectTableFindTreeNodesByParentId(String root, String type, String flag, String sOrt, String orgId) {
        String url = BASE_PATH + "/selectTableFindTreeNodesByParentId";
        Map<String,Object> map = new HashMap<>();
        map.put("root",root);
        map.put("type",type);
        map.put("flag",flag);
        map.put("sOrt",sOrt);
        map.put("orgId",orgId);
        ResponseMsg<List<TreeNode>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<List<TreeNode>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 获取公共字段信息
     * @return
     */
    public List<Map<String, Object>> getPublicFieldInfo() {
        String url = BASE_PATH + "/getPublicFieldInfo";
        ResponseMsg<List<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url,  new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     *获取字段对应设置数据
     * @param page
     * @param parameter
     * @return
     */
    public Page<Map<String, Object>> getPageRelateSetList(Paging<LantopFieldRelateSet> page, Map<String, Object> parameter) {
        String url = BASE_PATH + "/getPageRelateSetList";
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("parameter",parameter);
        ResponseMsg<Page<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Page<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *删除字段对应设置
     * @param ids
     */
    public void deleteMapSet(String ids) {
        String url = BASE_PATH + "/deleteMapSet";
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, ids, new ParameterizedTypeReference<ResponseMsg<T>>() {
        });
    }
}
